import ResultWrapper = require('../ResultWrapper')
import RequestResult = require("../RequestResult")
import RequestListResult = require("../RequestListResult")
import BaseModel = require('../BaseModel')
import Account = require('../model/Account')
//code1
import faker = require('faker')
//code1

/**
 * 登录
 */
class AccountApiLogin {
    
    get path(): string {
        return '/AccountApi/login'
    }
    
    get isUpload(): boolean {
        return false
    }

    setup(app: any, path: string) {
        console.log('setup service: /' + path)
    }

    //POST
    create(data: any, params: any) {
        return this.doWork(data)
    }

    doWork(params: any): Promise<any> {

        /**账号*/
        let account: string = params.account
        /**密码*/
        let password: string = params.password


        let callback = (
            resolve: (data: RequestResult<Account>) => void, 
            reject: (error: Error) => void) => {

            let data = new Account()
            let result = ResultWrapper.wrap(data)
            result.message = '假数据'

//code2
            faker.locale = "zh_CN";
            data.name = `${faker.name.firstName()} ${faker.name.lastName()}`

//code2
            resolve(result)
        }
        return new Promise(callback)
    }
}

export = AccountApiLogin